package com.mega.ycy.mixin;

import com.mega.ycy.Yiciyuan_EVENT;
import com.mega.ycy.common.event.SlashUpdateEvent;
import net.minecraft.entity.Entity;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@SuppressWarnings({"UnresolvedMixinReference", "MixinAnnotationTarget"})
@Mixin(Entity.class)
public class EntityMixin {
    @Inject(method = "<init>", at = @At("RETURN"))
    public void init(World worldIn, CallbackInfo ci) {
        Yiciyuan_EVENT.LOADED_ENTITIES.add((Entity) (Object)this);
    }

    /**
     * @author onEntityUpdate
     */
    @Inject(method = "func_70030_z", at = @At("HEAD"), cancellable = true)
    public void onEntityUpdate1(CallbackInfo ci) {
        if (Yiciyuan_EVENT.isSafe(this)) Yiciyuan_EVENT.protectEntity(this);
        else if (TWEAKER.isTimeStop) ci.cancel();
    }

    /**
     * @author onEntityUpdate
     */
    @Inject(method = "func_70030_z", at = @At("RETURN"))
    public void onEntityUpdate2(CallbackInfo ci) {
        if (Yiciyuan_EVENT.isSafe(this)) Yiciyuan_EVENT.protectEntity(this);
    }

    /**
     * @author setDead
     */
    @Inject(method = "func_70106_y", at = @At("HEAD"), cancellable = true)
    public void setDead(CallbackInfo ci) {
        if (Yiciyuan_EVENT.isSafe(this))
            ci.cancel();
    }

}
